<template>
  <div ref="mainDiv" class="scroll-wrap tenancy-block" style="height: 100%">
    <div class="datascreen-wrap" >
      <header-screen :user-info="userInfo" />
      <div class="data-container clearfix">
        <div class="container">
          <h4 class="title-txt">请选择您所要查看企业名称</h4>
          <el-row v-infinite-scroll="getEnterpriseList" :gutter="20" class="card-list2 scroll-wrap" infinite-scroll-disabled="disabled">
            <el-col v-for="(item,index) in enterpriseList" :key="index" :span="8">
              <div class="card" @click="chooseEnt(item)" style="cursor: pointer">
                <div class="card-pic">
                  <el-image :src="item.picture|imgPath">
                    <div slot="error" class="image-slot">
                      <img src="~@/assets/img/enterdefault.png" style="width: 100%">
                    </div>
                  </el-image>
                </div>
                <div class="card-body">
                  <div class="title text-ellipsis">
                    {{ item.name }}
                  </div>
                  <div class="txt text-ellipsis">
                    单位电话: {{ item.phone }}
                  </div>
                  <div class="txt text-ellipsis">
                    <i class="iconfont icon-weizhi" />{{ item.provinceName }}{{ item.cityName }}{{ item.countyName }}{{ item.streetName }}{{ item.address }}
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import HeaderScreen from '../screen/header/header-screen'
import { postHandle } from '@/api'
export default {
  components: { HeaderScreen },
  data() {
    return {
      enterpriseList: [],
      page: {
        ps: 9,
        p: 1
      },
      total: 0,
      loading: false
    }
  },
  computed: {
    userInfo() {
      return this.$store.state.user
    },
    noMore() {
      return this.enterpriseList.length >= this.total
    },
    disabled() {
      return this.loading || this.noMore
    }
  },
  created() {
    this.getEnterpriseList()
  },
  methods: {
    getEnterpriseList() {
      this.loading = true
      postHandle('/api/v1/welder-sbtx-second/enterprise-comb/list', {
        d: {
          page: {
            ps: this.page.ps,
            p: this.page.p

          },
          // sorts: [
          //   { field: 'startTime', isDesc: true }
          // ],
          retPage: true
        }
      }).then(res => {
        this.loading = false
        this.enterpriseList = this.enterpriseList.concat(res.result)
        this.total = res.page.ts
        if (!this.noMore) {
          this.page.p++
        }
      })
    },
    chooseEnt(item) {
      this.$store.commit('enterprise/SET_ENTSPACEID', item.spaceId)
      this.$store.commit('enterprise/SET_ENT_OBJ', item)
      this.$router.push('/')
    }
  }
}
</script>

<style>
  .tenancy-block .card-pic .el-image{
    width: 100%;
  }
</style>
